package com.pxmeta.party.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxmeta.party.entity.SkillPrice;
import com.pxmeta.party.entity.vo.ServiceOvertimeFeeVO;
import com.pxmeta.party.mapper.SkillPriceMapper;
import com.pxmeta.party.service.ISkillPriceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class SkillPriceServiceImpl extends ServiceImpl<SkillPriceMapper, SkillPrice> implements ISkillPriceService {

    private static final Integer TYPE_INTERACTION = 1;//语音互动

    private static final Integer TYPE_ORDER = 2; //陪玩订单


    @Override
    public List<ServiceOvertimeFeeVO> getListBySkillId(Integer skillId) {
        LambdaQueryWrapper<SkillPrice> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SkillPrice::getSkillId, skillId)
                .eq(SkillPrice::getType,TYPE_INTERACTION)
                .orderByAsc(SkillPrice::getPrice);
        List<SkillPrice> list = this.list(wrapper);

        return list.stream().map(l -> {
            ServiceOvertimeFeeVO vo = new ServiceOvertimeFeeVO();
            vo.setPrice(l.getPrice());
            vo.setServicePriceId(l.getId());
            vo.setDuration(l.getDuration());
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public SkillPrice getDefaultBySkillId(Integer skillId) {
        LambdaQueryWrapper<SkillPrice> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SkillPrice::getSkillId, skillId)
                .eq(SkillPrice::getIsDefault, Boolean.TRUE);
        return this.getOne(wrapper);
    }
}
